/**
 * WebsiteItem
 */

 import Validator from "../../../../../utils/validator/Validator";
// var dataProvider = require("../../../provider/dataProvider");
 import React,{Component}from "react";

 class PagejumpItem extends Component{
    constructor(props) {
        super(props);
        this.state = {             
            pageIndex: ""
        };
    }
    componentWillMount(){
        const {data} = this.props;
        this.pageIndex = data.action.page_index || "";
        this.setState({
            pageIndex: this.pageIndex
        });
    }
    saveData(){
        let pageIndex = this.pageIndex;
        const {data,updateWidget,setState} = this.props;
        data.action.page_index = pageIndex;

        setState({selectedWidget: data});
        updateWidget(data);
    }
    handleOnChangePageIndex(e){
        let element = $(e.target || e.srcElement);
        this.pageIndex = element.val();
        this.setState({
            pageIndex: this.pageIndex
        });
        this.saveData();
    }
    render(){
        const {data,pages} = this.props;
        return (
            <div className="pagejump-container">
                <span>{$._('Page to')}</span>
                <select onChange={(e) => this.handleOnChangePageIndex(e)} value={this.state.pageIndex}>
                {
                    pages.map(function (page){
                        return (
                            <option key={page.page_id} value={page.page_id}>
                                {$._("No.")}{page.title}{$._("Page")}
                            </option>
                        )
                    })
                }
                </select>
            </div>
        )
    }
 }

 module.exports = PagejumpItem;
